package com.cn.lg.controller;

import com.alibaba.fastjson.JSONObject;
import com.cn.lg.common.Page;
import com.cn.lg.model.Student;
import com.cn.lg.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2017/7/12.
 */
@Controller
@RequestMapping("student")
public class StudentController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private StudentService studentService;

    @RequestMapping("getStudent")
    @ResponseBody
    public String getStudent(Page page){
        JSONObject jsonObject = new JSONObject();
        PageHelper.startPage(page.getPageNum(),page.getSize());
        List<Student> students = studentService.findStudent();
        PageInfo<Student> pageInfo = new PageInfo<Student>(students);
        System.out.print(pageInfo);
        jsonObject.put("result",pageInfo);
        return jsonObject.toString();
    }
}
